table of contents
SYSTEMD-CRYPTENROLL(1) | systemd-cryptenroll | SYSTEMD-CRYPTENROLL(1) |
NAME¶
systemd-cryptenroll - Enroll PKCS#11, FIDO2, TPM2 token/devices to LUKS2 encrypted volumes
SYNOPSIS¶
systemd-cryptenroll [OPTIONS...] [DEVICE]
DESCRIPTION¶
systemd-cryptenroll is a tool for enrolling hardware security tokens and devices into a LUKS2 encrypted volume, which may then be used to unlock the volume during boot. Specifically, it supports tokens and credentials of the following kind to be enrolled:
In addition, the tool may be used to enumerate currently enrolled security tokens and wipe a subset of them. The latter may be combined with the enrollment operation of a new security token, in order to update or replace enrollments.
The tool supports only LUKS2 volumes, as it stores token meta-information in the LUKS2 JSON token area, which is not available in other encryption formats.
TPM2 PCRs and policies¶
PCRs allow binding of the encryption of secrets to specific software versions and system state, so that the enrolled key is only accessible (may be "unsealed") if specific trusted software and/or configuration is used. Such bindings may be created with the option --tpm2-pcrs= described below.
Secrets may also be bound indirectly: a signed policy for a state of some combination of PCR values is provided, and the secret is bound to the public part of the key used to sign this policy. This means that the owner of a key can generate a sequence of signed policies, for specific software versions and system states, and the secret can be decrypted as long as the machine state matches one of those policies. For example, a vendor may provide such a policy for each kernel+initrd update, allowing users to encrypt secrets so that they can be decrypted when running any kernel+initrd signed by the vendor. Such bindings may be created with the options --tpm2-public-key=, --tpm2-public-key-pcrs=, --tpm2-signature= described below.
See Linux TPM PCR Registry[1] for an authoritative list of PCRs and how they are updated. The table below contains a quick reference, describing in particular the PCRs modified by systemd.
Table 1. Well-known PCR Definitions
PCR | name | Explanation |
0 | platform-code | Core system firmware executable code; changes on firmware updates |
1 | platform-config | Core system firmware data/host platform configuration; typically contains serial and model numbers, changes on basic hardware/CPU/RAM replacements |
2 | external-code | Extended or pluggable executable code; includes option ROMs on pluggable hardware |
3 | external-config | Extended or pluggable firmware data; includes information about pluggable hardware |
4 | boot-loader-code | Boot loader and additional drivers, PE binaries invoked by the boot loader; changes on boot loader updates. sd-stub(7) measures system extension images read from the ESP here too (see systemd-sysext(8)). |
5 | boot-loader-config | GPT/Partition table; changes when the partitions are added, modified, or removed |
7 | secure-boot-policy | Secure Boot state; changes when UEFI SecureBoot mode is enabled/disabled, or firmware certificates (PK, KEK, db, dbx, ...) changes. |
9 | kernel-initrd | The Linux kernel measures all initrds it receives into this PCR. |
10 | ima | The IMA project measures its runtime state into this PCR. |
11 | kernel-boot | systemd-stub(7) measures the ELF kernel image, embedded initrd and other payload of the PE image it is placed in into this PCR. systemd-pcrphase.service(8) measures boot phase strings into this PCR at various milestones of the boot process. |
12 | kernel-config | systemd-boot(7) measures the kernel command line into this PCR. systemd-stub(7) measures any manually specified kernel command line (i.e. a kernel command line that overrides the one embedded in the unified PE image) and loaded credentials into this PCR. |
13 | sysexts | systemd-stub(7) measures any systemd-sysext(8) images it passes to the booted kernel into this PCR. |
14 | shim-policy | The shim project measures its "MOK" certificates and hashes into this PCR. |
15 | system-identity | systemd-cryptsetup(8) optionally measures the volume key of activated LUKS volumes into this PCR. systemd-pcrmachine.service(8) measures the machine-id(5) into this PCR. systemd-pcrfs@.service(8) measures mount points, file system UUIDs, labels, partion UUIDs of the root and /var/ filesystems into this PCR. |
16 | debug | Debug |
23 | application-support | Application Support |
In general, encrypted volumes would be bound to some combination
of PCRs 7, 11, and 14 (if shim/MOK is used). In order to allow firmware and
OS version updates, it is typically not advisable to use PCRs such as 0 and
2, since the program code they cover should already be covered indirectly
through the certificates measured into PCR 7. Validation through
certificates hashes is typically preferable over validation through direct
measurements as it is less brittle in context of OS/firmware updates: the
measurements will change on every update, but signatures should remain
unchanged. See the
Linux TPM PCR Registry[1] for more discussion.
LIMITATIONS¶
Note that currently when enrolling a new key of one of the five supported types listed above, it is required to first provide a passphrase or recovery key (i.e. one of the latter two key types). For example, it's currently not possible to unlock a device with a FIDO2 key in order to enroll a new FIDO2 key. Instead, in order to enroll a new FIDO2 key, it is necessary to provide an already enrolled regular passphrase or recovery key. Thus, if in future key roll-over is desired it's generally recommended to combine TPM2, FIDO2, PKCS#11 key enrollment with enrolling a regular passphrase or recovery key.
Also note that support for enrolling multiple FIDO2 tokens is currently not too useful, as while unlocking systemd-cryptsetup cannot identify which token is currently plugged in and thus does not know which authentication request to send to the device. This limitation does not apply to tokens enrolled via PKCS#11 — because tokens of this type may be identified immediately, before authentication.
OPTIONS¶
The following options are understood:
--password
--recovery-key
--unlock-key-file=PATH
--pkcs11-token-uri=URI
In order to unlock a LUKS2 volume with an enrolled PKCS#11 security token, specify the pkcs11-uri= option in the respective /etc/crypttab line:
myvolume /dev/sda1 - pkcs11-uri=auto
See crypttab(5) for a more comprehensive example of a systemd-cryptenroll invocation and its matching /etc/crypttab line.
--fido2-credential-algorithm=STRING
"es256" denotes ECDSA over NIST P-256 with SHA-256. "rs256" denotes 2048-bit RSA with PKCS#1.5 padding and SHA-256. "eddsa" denotes EDDSA over Curve25519 with SHA-512.
Note that your authenticator may not support some algorithms.
--fido2-device=PATH
In order to unlock a LUKS2 volume with an enrolled FIDO2 security token, specify the fido2-device= option in the respective /etc/crypttab line:
myvolume /dev/sda1 - fido2-device=auto
See crypttab(5) for a more comprehensive example of a systemd-cryptenroll invocation and its matching /etc/crypttab line.
--fido2-with-client-pin=BOOL
--fido2-with-user-presence=BOOL
--fido2-with-user-verification=BOOL
--tpm2-device=PATH
In order to unlock a LUKS2 volume with an enrolled TPM2 security chip, specify the tpm2-device= option in the respective /etc/crypttab line:
myvolume /dev/sda1 - tpm2-device=auto
See crypttab(5) for a more comprehensive example of a systemd-cryptenroll invocation and its matching /etc/crypttab line.
Use --tpm2-pcrs= (see below) to configure which TPM2 PCR indexes to bind the enrollment to.
--tpm2-device-key=PATH
The key, in most cases, should be the Storage Root Key (SRK) from the TPM2 security chip. If a key from a different handle (not the SRK) is used, you must specify its handle index using --tpm2-seal-key-handle=.
You may use tpm2-tss tools to get the SRK from the TPM2 security chip with tpm2_readpublic(1), for example:
tpm2_readpublic -c 0x81000001 -o srk.pub
--tpm2-seal-key-handle=HANDLE
The default is the Storage Root Key (SRK) handle index "0x81000001". A value of 0 will use the default. For the SRK handle, a new key will be created and stored in the TPM if one does not already exist; for any other handle, the key must already exist in the TPM at the specified handle index.
This should not be changed unless you know what you are doing.
--tpm2-pcrs= [PCR...]
Example: --tpm2-pcrs=boot-loader-code+platform-config+boot-loader-config specifies that PCR registers 4, 1, and 5 should be used.
Example: --tpm2-pcrs=7:sha256 specifies that PCR register 7 from the SHA256 bank should be used.
Example: --tpm2-pcrs=4:sha1=3a3f780f11a4b49969fcaa80cd6e3957c33b2275 specifies that PCR register 4 from the SHA1 bank should be used, and a hash digest value of 3a3f780f11a4b49969fcaa80cd6e3957c33b2275 will be used instead of reading the current PCR value.
--tpm2-with-pin=BOOL
Note that incorrect PIN entry when unlocking increments the TPM dictionary attack lockout mechanism, and may lock out users for a prolonged time, depending on its configuration. The lockout mechanism is a global property of the TPM, systemd-cryptenroll does not control or configure the lockout mechanism. You may use tpm2-tss tools to inspect or configure the dictionary attack lockout, with tpm2_getcap(1) and tpm2_dictionarylockout(1) commands, respectively.
--tpm2-public-key= [PATH], --tpm2-public-key-pcrs= [PCR...], --tpm2-signature= [PATH]
Note the difference between --tpm2-pcrs= and --tpm2-public-key-pcrs=: the former binds decryption to the current, specific PCR values; the latter binds decryption to any set of PCR values for which a signature by the specified public key can be provided. The latter is hence more useful in scenarios where software updates shell be possible without losing access to all previously encrypted LUKS2 volumes. Like with --tpm2-pcrs=, names defined in the table above can also be used to specify the registers, for instance --tpm2-public-key-pcrs=boot-loader-code+system-identity.
The --tpm2-signature= option takes a path to a TPM2 PCR signature file as generated by the systemd-measure(1) tool. If this is not specified explicitly, a suitable signature file tpm2-pcr-signature.json is searched for in /etc/systemd/, /run/systemd/, /usr/lib/systemd/ (in this order) and used. If a signature file is specified or found it is used to verify if the volume can be unlocked with it given the current PCR state, before the new slot is written to disk. This is intended as safety net to ensure that access to a volume is not lost if a public key is enrolled for which no valid signature for the current PCR state is available. If the supplied signature does not unlock the current PCR state and public key combination, no slot is enrolled and the operation will fail. If no signature file is specified or found no such safety verification is done.
--wipe-slot= [SLOT...]
This switch may be used alone, in which case only the requested wipe operation is executed. It may also be used in combination with any of the enrollment options listed above, in which case the enrollment is completed first, and only when successful the wipe operation executed — and the newly added slot is always excluded from the wiping. Combining enrollment and slot wiping may thus be used to update existing enrollments:
systemd-cryptenroll /dev/sda1 --wipe-slot=tpm2 --tpm2-device=auto
The above command will enroll the TPM2 chip, and then wipe all previously created TPM2 enrollments on the LUKS2 volume, leaving only the newly created one. Combining wiping and enrollment may also be used to replace enrollments of different types, for example for changing from a PKCS#11 enrollment to a FIDO2 one:
systemd-cryptenroll /dev/sda1 --wipe-slot=pkcs11 --fido2-device=auto
Or for replacing an enrolled empty password by TPM2:
systemd-cryptenroll /dev/sda1 --wipe-slot=empty --tpm2-device=auto
-h, --help
--version
EXIT STATUS¶
On success, 0 is returned, a non-zero failure code otherwise.
SEE ALSO¶
systemd(1), systemd-cryptsetup@.service(8), crypttab(5), cryptsetup(8), systemd-measure(1)
NOTES¶
- 1.
- Linux TPM PCR Registry
systemd 252 |